<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function childNum(num, count) {
            let allplayer = []
            for (let i = 0; i < num; i++) {
                allplayer[i] = i + 1
            }
            let exitCount = 0
            let counter = 0
            let curIndex = 0
            while (exitCount < num - 1) {
                if (allplayer[curIndex] !== 0) counter++;

                //报数到count
                if (counter === count) {
                    allplayer[curIndex] = 0;
                    counter = 0;
                    exitCount += 1;
                }

                curIndex++;
                if (curIndex == num) {
                    curIndex = 0;
                }
            }
            for (let i = 0; i < num; i++) {
                if (allplayer[i] !== 0) {
                    return i+1;
                }
            }
        }
        console.log(childNum(30,3))
    </script>
</body>

</html>